package evi.com.evi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import evi.com.evi.R;
import evi.com.evi.activity.SearchActivity;
import evi.com.evi.bean.SubOrderDetailBean;

public class GridGoodsAdapter<T> extends BaseAdapter{

	private Context mContext;
	private List<T> mList;

	public GridGoodsAdapter(Context context, List<T> mList) {
		this.mContext = context;
		this.mList = mList;
		if(this.mList == null){
			this.mList = new ArrayList<T>();
		}
	}
	
	@Override
	public int getCount() {
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null){
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.item_gv_goods, null);
			
			viewHolder.item_record = (TextView) convertView.findViewById(R.id.item_record);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}

		SubOrderDetailBean data = (SubOrderDetailBean) mList.get(position);
		viewHolder.item_record.setText(data.getProductName() + " ×" + data.getProductCount());

		viewHolder.item_record.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
			}
		});
		
		return convertView;
	}
	
	class OnitemListener implements OnClickListener{
		
		private int position;
		private Object obj;

		public OnitemListener(int position, Object obj){
			this.position = position;
			this.obj = obj;
		}
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.item_record:
				String info = (String) obj;
				((SearchActivity)mContext).searchData(info);
				break;
			default:
				break;
			}
		}
		
	}
	
	class ViewHolder{
		TextView item_record;
	}

}
